<template>
	<view class="wrapper p-2">
		<view>
			<h4 class="fs-28 mb-4">实名认证（请上传真实的个人信息，认证通过后将无法修改）</h4>
			<view class="bg-white p-2 rounded">
				<uni-forms :model="ruleForm" label-width="200rpx" ref="uForm">
					<uni-forms-item label="姓名" name="real_name" class="border-bottom">
						<input v-model="ruleForm.real_name" :disabled="ruleForm.id?true:false" placeholder="请输入您的真实姓名" />
					</uni-forms-item>
					<uni-forms-item label="身份证" name="id_card" class="border-bottom">
						<input v-model="ruleForm.id_card" :disabled="ruleForm.id?true:false" placeholder="请输入身份证号码" />
					</uni-forms-item>
				</uni-forms>
				<view v-if="!ruleForm.id" class="rounded-circle text-center py-1 bge87722 text-white" @click="submit">提交
				</view>
			</view>
		</view>

		<view class="tips">
			<!-- <view>您提交的信息正在审核</view> -->
			<view>提交认证申请后，工作人员将在三个工作日进行核对完成审核</view>
		</view>
	</view>
</template>
<script>
	import {
		applyDistribution,
		distribution
	} from "@/api/goods";
	import {
		checkBankno
	} from "@/utils/Foundation";
	export default {
		data() {
			return {
				ruleForm: {
					real_name: "",
					id_card: "",
				},
				rules: {
					// 对name字段进行必填验证
					real_name: {
						rules: [{
								required: true,
								errorMessage: '请输入姓名',
							},
							{
								minLength: 2,
								maxLength: 10,
								errorMessage: '姓名长度在 {minLength} 到 {maxLength} 个字符',
							}
						]
					},
					// 对email字段进行必填验证
					id_card: {
						rules: [{
							required: true,
							errorMessage: '请输入身份证号',
						}]
					}
				},
			};
		},
		created() {
			this.distribution()
		},
		methods: {
			distribution() {
				distribution().then(res => {
					if (res.code == 1) {
						this.ruleForm = {
							...res.data
						}
					}
				})
			},
			submit() {
				this.$refs.uForm.validate().then((valid) => {
					applyDistribution(this.ruleForm).then((res) => {
						if (res.code === 1) {
							uni.showToast({
								title: "认证提交成功!",
								duration: 2000,
								icon: "none",
							});

							setTimeout(() => {
								uni.navigateBack();
							}, 500);
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						}
					});
				}).catch(err => {

				});
			},
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
	};
</script>
<style lang="scss" scoped>
	.tips {
		margin-top: 20rpx;
		font-size: 24rpx;
		color: #999;
	}
</style>